package cn.bluemobi.app.utils;

public class Base64Utils {
    @SuppressWarnings("restriction")
    public static String getBASE64(String s) {
        if (s == null)
            return null;
        return (new sun.misc.BASE64Encoder()).encode(s.getBytes());
    }

    // 将 BASE64 编码的字符串 s 进行解码 解密
    @SuppressWarnings("restriction")
    public static String getFromBASE64(String s) {
        if (s == null)
            return null;
        sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
        try {
            byte[] b = decoder.decodeBuffer(s);
            return new String(b);
        } catch (Exception e) {
            return null;
        }
    }

    public static String mTOa(Object ming) {
        return Base64Utils.getBASE64(Base64Utils.getBASE64(Base64Utils.getBASE64((String) ming)));
    }

    public static String aTOm(String an) {
        return Base64Utils.getFromBASE64(Base64Utils.getFromBASE64(Base64Utils.getFromBASE64(an)));
    }

    public static void main(String[] args) {
        String a = mTOa("{\"name\":\"张三\",\"age\":10}");
        System.out.println(a);// 加密
        System.out.println(aTOm(a));// 解密
    }
}
